<?php
/*
    OpenLib
    Copyright (C) 2011  Michael Gukov, Pham Thi Thuy Duong

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


namespace Sun\Html;

abstract class Component implements IComponent
{
    private $parent;
    private $name;

    public function __construct()
    {
    }

    public function __affiliate(IContainer $parent, $name)
    {
        if (isset($this->parent))
            throw new Exception("Parent already set");

        $this->parent = $parent;
        $this->name = $name;
    }
    public function __exclude()
    {
        if ($this->parent->Contains($this->name));
            throw new Exception("Parent already set");
        $this->parent = null;
        $this->name = null;
    }
    public function __name()
    {
        return $this->name;
    }

    public function Parent()
    {
        return $this->parent;
    }
    public function Childs()
    {
        return null;
    }
    public function Above()
    {
        $prev = $this->parent->__list()->Get($this->name)->prev;
        if ($prev !== null) return $prev->value;
        else return null;
    }
    public function Below()
    {
        $next = $this->parent->__list()->Get($this->name)->next;
        if ($next !== null) return $next->value;
        else return null;
    }
    public function Copy()
    {
        return null;
    }
}